package com.hrms.controller;

import com.hrms.domain.Department;
import com.hrms.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author:zhao xinyu
 * @date: 2024/12/19 - 09:08
 * @mail: zxy1277692924@outlook.com
 * @info:
 */
@RequestMapping("/admin/department")
@RestController
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @GetMapping("/list")
    public Map list(){
        List<Department> departments =departmentService.queryList();
        Map<String,Object> result = new HashMap<>();
        result.put("msg","操作成功");
        result.put("code",200);
        result.put("data",departments);

        return result;
    }
    @GetMapping("{deptNo}")
    public Map getDeptNo(@PathVariable Integer deptNo){
        Department department =departmentService.queryDeptByNo(deptNo);
        Map<String,Object> result = new HashMap<>();
        result.put("msg","操作成功");
        result.put("code",200);
        result.put("data",department);

        return result;
    }

    @PostMapping()
    public Map saveDept(@RequestBody Department department){
        int isSuccess = departmentService.saveDept(department);
        Map<String,Object> result = new HashMap<>();
        if (isSuccess==0){
            result.put("msg","操作失败");
            result.put("code",100);
            result.put("data",null);
        }else{
            result.put("msg","操作成功");
            result.put("code",200);
            result.put("data",null);
        }


        return result;
    }

}
